package bookstudytest.functioninterface;

import java.util.function.Function;

/**
 * @Author li.heng
 * @Date 2019/6/21 15
 * @Description:
 **/
public class FunctionDemo {
    public static void main(String[] args) {
        // 返回参数本身的function
        Function<Object, Object> identity = Function.identity();
        // 定义一个有逻辑的function
        Function<String, String> a = (s)->s+" 11111111";
        // 定义一个有后续逻辑的function，先执行的function的返回值就是后执行的function的参数，类型需要匹配
        Function<String, String> function = a.andThen((s) -> s+" 33333333");
        // 定义一个有前置逻辑的function，前置执行的function的返回值就是该function的参数
        Function<Object, String> compose = a.compose((s) -> s + " 222222");
        System.out.println(compose.apply("aaa"));
        Function<Object, String> compose1 = function.compose((s) -> s + " 4444444");
        System.out.println(compose1.apply("aaa"));
    }
}
